﻿using System;
using System.Diagnostics;
using CefSharp;

namespace pinduoduo.Util
{
    public class CefUtils
    {
        private static RequestContext AccountContext;

        private CefUtils() 
        {
        }

        public static RequestContext GetAccountContext() 
        {
            if (AccountContext == null) 
            {
                AccountContext = new RequestContext(new RequestContextSettings()
                {
                    CachePath = AppDomain.CurrentDomain.BaseDirectory + "caches\\global2\\",
                    PersistSessionCookies = true,
                    PersistUserPreferences = true
                });
            }

            return AccountContext;
        }


        public static void KillDriver() 
        {
            var processes = Process.GetProcessesByName("chromedriver");
            foreach (var processe in processes)
            {
                try
                {
                    processe.Kill();
                }
                catch
                {
                }
            }
        }
    }
}
